﻿using Sidvall.IdentityManager.Data;

namespace Sidvall.IdentityManager.UI.Entities
{
	public partial class AspNetUsersCollection
	{
		#region Public Members

		#region Import

		public void Import(PluginFilter pluginFilter, bool removeItems)
		{
			if (pluginFilter == null)
				return;
			if (pluginFilter.FilterResult == null)
				return;
			Import(pluginFilter.FilterResult.Users, pluginFilter.FilterIndex, removeItems);
		}
		public void Import(PluginUserCollection users, int pluginIndex, bool removeItems)
		{
			PluginUser pluginUser;
			AspNetUsers item;
			int iMax;

			if (users == null)
			{
				if (removeItems)
					Clear();
				return;
			}
			iMax = this.Count;
			for (int i = iMax - 1; i >= 0; i--)
			{
				item = this[i];
				pluginUser = users.FindItemById(item.Id);
				if (pluginUser != null)
				{
					Sidvall.SystemContext.Current.CodeManager.SetPropertyValue(item, pluginUser.Data1, "Plugin" + (pluginIndex + 1).ToString() + "ColumnData1");
					Sidvall.SystemContext.Current.CodeManager.SetPropertyValue(item, pluginUser.Data2, "Plugin" + (pluginIndex + 1).ToString() + "ColumnData2");
					Sidvall.SystemContext.Current.CodeManager.SetPropertyValue(item, pluginUser.Data3, "Plugin" + (pluginIndex + 1).ToString() + "ColumnData3");
				}
				else if (removeItems)
				{
					Remove(item);
				}
			}
		}

		#endregion

		#endregion
	}
}